/**
 * @Description:计算应缴税款总额
 * @Date:Create in 19:59  2022/6/13
 */
public class calculateTax2303 {
    public static void main(String[] args) {
        int[][] brackets = {{3, 50}, {7, 10}, {12, 25}};
        int income = 2;
        System.out.println(income/100);
        System.out.println(calculateTax1(brackets, income));
    }

    public static double calculateTax1(int[][] brackets, int income) {
        double sum = 0;
        int b = 0;
        int size = brackets.length;
        boolean flag = false;
        if(income<=brackets[0][0]){
            sum += new Double(income * brackets[0][1])/100;
//            return sum;
        }else{
            for (int i = 0; i < brackets.length; i++) {
                System.out.println(brackets[i][0]);
                if (brackets[i][0] <= income) {
                    sum += new Double((brackets[i][0] - b) * brackets[i][1])/100 ;
                    b = brackets[i][0];
                } else {
                    sum += new Double((income - brackets[i-1][0]) * brackets[i][1])/100;
//                b = income;
                    flag = true;
                    break;
                }
                System.out.println(sum);

//            if (brackets[i + 1][0] >= income && i == brackets.length - 2) {
//                sum += new Double((brackets[i][0] - income) * brackets[i][1]/100);
//                flag = true;
//            }
//            System.out.println(sum);
            }
            if (!flag) {
//            sum += new Double((brackets[size - 1][0] - brackets[size - 2][0]) * brackets[size - 2][1])/100;
                sum += new Double((income - brackets[size - 1][0]) * brackets[size - 1][1])/100;
            }
        }

        return sum;
    }
}
